package com.itheima.electronicbusinesssystem;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;

public class Test {
    public static void main(String[] args) {

        ArrayList<Product> list=new ArrayList<>();
        // * 商品类：编号、名字、种类、价格、销量、库存
        list.add(new Product(getId(list),"苹果14","电子产品",5999.0,199,500));
        list.add(new Product(getId(list),"苹果14","电子产品",5999.0,199,500));
        list.add(new Product(getId(list),"苹果14","电子产品",5999.0,199,500));
        list.add(new Product(getId(list),"苹果14","电子产品",5999.0,199,500));


    }


    //降序


    //生成商品编号
    public static String getId(ArrayList<Product> list){
        Random random=new Random();

        while (true) {
            String str=(random.nextInt(9)+1)+"";
            for (int i = 0; i < 8; i++) {
                int num=random.nextInt(9);
                str+=num;
            }

            int judge = judge(list, str);
            if (judge==-1){
                return str;
            }
        }

    }

    //判断是否重复
    public static int judge(ArrayList<Product> list,String str){
        for (int i = 0; i < list.size(); i++) {
            if (true==list.get(i).getId().equals(str)){
                return  i;
            }
        }
        return -1;
    }
}
